package com.itheima.controller;


import com.itheima.pojo.Order;
import com.itheima.pojo.User;
import com.itheima.service.OrderService;
import com.itheima.service.UserServiceImpl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserServiceImpl userServiceImpl;

    @Autowired
    private OrderService orderService;

    @GetMapping("/{id}")
    public HashMap<User, List<Order>> queryById(@PathVariable("id") String username, HttpServletRequest request) {
        String value = request.getHeader("name");
        System.out.println("value = " + value);

        User user = userServiceImpl.queryById(username);
        List<Order> orderList = orderService.findOrderByUserName(username);
        HashMap<User, List<Order>> map = new HashMap<>();
        map.put(user, orderList);
        return map;
    }
}